package com.github.freegeese.maven.plugin.autocode.demo.base;


import org.springframework.web.bind.annotation.*;

/**
 * 基础的控制层，集成增删改查基础接口
 *
 * @param <S>  业务Service
 * @param <M>  持久化Mapper
 * @param <E>  实体Entity
 * @param <ID> 实体主键ID
 */
public abstract class SortableController<S extends SortableService<M, E, ID>, M extends SortableMapper<E, ID>, E extends Sortable<ID>, ID> extends BaseController<S, M, E, ID> {

    @RequestMapping(value = "/exchange/{source}/{target}", method = RequestMethod.PUT)
    @ResponseBody
    public Object exchange(@PathVariable("source") ID source, @PathVariable("target") ID target) {
        S service = getService();
        return service.exchange(service.selectByPrimaryKey(source), service.selectByPrimaryKey(target));
    }

    @RequestMapping(value = "/move/{from}/{to}", method = RequestMethod.PUT)
    @ResponseBody
    public Object move(@PathVariable("from") ID from, @PathVariable("to") ID to) {
        S service = getService();
        return service.move(service.selectByPrimaryKey(from), service.selectByPrimaryKey(to));
    }

    @RequestMapping(value = "/top/{id}", method = RequestMethod.PUT)
    @ResponseBody
    public Object top(@PathVariable("id") ID id) {
        S service = getService();
        return service.top(service.selectByPrimaryKey(id));
    }

    @RequestMapping(value = "/up/{id}", method = RequestMethod.PUT)
    @ResponseBody
    public Object up(@PathVariable("id") ID id) {
        S service = getService();
        return service.up(service.selectByPrimaryKey(id));
    }

    @RequestMapping(value = "/down/{id}", method = RequestMethod.PUT)
    @ResponseBody
    public Object down(@PathVariable("id") ID id) {
        S service = getService();
        return service.down(service.selectByPrimaryKey(id));
    }

    @RequestMapping(value = "/bottom/{id}", method = RequestMethod.PUT)
    @ResponseBody
    public Object bottom(@PathVariable("id") ID id) {
        S service = getService();
        return service.bottom(service.selectByPrimaryKey(id));
    }

}
